package com.wyl.jetpack.lifecycle


import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.findNavController
import com.wyl.jetpack.R
import com.wyl.baselib.base.BaseFragment
import kotlinx.android.synthetic.main.fragment_lifecycle.*

/**
 * A simple [Fragment] subclass.
 */
class LifecycleFragment : BaseFragment() {

    private val observer by lazy { MyLifecycleObserver() }

    init {
        lifecycle.addObserver(observer)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        lifecycle.addObserver(observer)
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_lifecycle, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        button3.setOnClickListener {
            findNavController().navigate(R.id.action_lifecycleFragment_to_nav_nav2)
        }

    }

}
